//Copyright © 2012 Ryan Larson, Ben Glasser
//[This program is licensed under the "GPL v3.0 License"]
// Please see the file COPYING in the source
//distribution of this software for license terms.
package org.app_chat.service;

import java.lang.reflect.ParameterizedType;

import org.app_chat.api.Listener;

/**
 * Copyright (c) 2012 Ryan Larson, Ben Glasser
 * Created by Ryan of app-chat.org
 * on: 8/8/12 at 10:14 AM
 */

/**
 * Reflection helper class to get the parametrized types of interfaces
 * to be able to rebuild the messages as they come across the wire.
 */
public class ReflectionUtils {

    /**
     * This will take an {@link Listener} and return the {@link ParameterizedType}
     *
     * @param listener {@link Listener} that we need the message type from
     * @return {@link Class} type parameter of the {@link Listener}
     */

    public static Class<?> getParameterizedTypeFromInterface(Listener listener) {
        return (Class<?>) ((ParameterizedType) listener.getClass().getGenericInterfaces()[0]).getActualTypeArguments()[0];
    }
}
